// https://leetcode.cn/problems/kth-largest-element-in-a-stream/
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

class KthLargest {
public:
	int k = 0;
	priority_queue<int, vector<int>, greater<int>> q;
    KthLargest(int k, vector<int>& nums) {
		this->k = k;
		for(auto & x:nums){
			add(x);
		}
    }
    
    int add(int val) {
		q.push(val);
		if(q.size() > k){
			q.pop();
		}
		return q.top();
    }
};

int main(){
	vector<int> nums = {3,4};
	KthLargest* obj = new KthLargest(2, nums);
	cout << obj->add(1) << endl;
	cout << obj->add(3) << endl;
	return 0;
}